package com.allwees.bs.module.ums.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.allwees.bs.module.ums.entity.Customer;
import com.allwees.bs.module.ums.req.query.CustomerQueryReq;
import com.allwees.core.dao.mybatis.dao.BaseDao;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CustomerDao extends BaseDao<Customer> {

    Page<Customer> page(Page<Customer> page, @Param("req") CustomerQueryReq req);

    default Integer findCountByPromoCode(String promoCode) {
        if (StringUtils.isBlank(promoCode)) {
            return 0;
        }
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("promo_code", promoCode);
        return selectCount(wrapper);
    }


    default Integer findCountByShareCode(String shareCode) {
        if (StringUtils.isBlank(shareCode)) {
            return 0;
        }
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("share_code", shareCode);
        return selectCount(wrapper);
    }

    @Select({"select * from usr_user "})
    List<Customer> findAll();
}
